<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//平台注册绑定表
class Plat_cpa_model extends CI_Model{
    function __construct() {
        parent::__construct();
        $this->plat_ac_cpa_table = 'plat_ac_cpa';//理财AC类型的cpa
        $this->plat_ab_cpa_table = 'plat_ab_cpa';//理财AB类型的cpa
        $this->plat_table = "plat";
        $this->users_table = 'users';
        
    }
    function get_ab_user_info($where){
        $this->db->select('*');
        $this->db->from($this->plat_ab_cpa_table);
        $this->db->where($where);
        $query = $this->db->get();
        return $query->row_array();
    }
    
    //通过手机前三位和后三位查找用户信息
    function get_users_by_mobile_3_to_3($mobile_first,$mobile_end,$plat_en){
        $sql = "select * from tan_plat_ab_cpa where usernamep like '".$mobile_first."%' and usernamep like '%".$mobile_end."' and plat_en = '".$plat_en."'";
        $query = $this->db->query($sql);
        return $query->row_array();
    }
    
    function get_ac_user_info($where){
        $this->db->select('*');
        $this->db->from($this->plat_ac_cpa_table);
        $this->db->where($where);
        $query = $this->db->get();
        return $query->row_array();
    }
    function get_ac_cpa_list($where,$page,$limit){
        $this->db->select($this->plat_ac_cpa_table.'.*,'.$this->users_table.".username,".$this->plat_table.".name_ch,".$this->plat_table.".name_en");
        $this->db->from($this->plat_ac_cpa_table);
        $this->db->join($this->users_table,$this->users_table.'.user_id = '.$this->plat_ac_cpa_table.'.user_id');
        $this->db->join($this->plat_table,$this->plat_table.'.id = '.$this->plat_ac_cpa_table.'.plat_id');
        $this->db->where($where);
        $this->db->order_by('id','desc');
        $this->db->limit($limit, $page);
        return $this->db->get()->result_array();
    }
    
    function get_ac_cpa_count($where){
        $this->db->select('*');
        $this->db->from($this->plat_ac_cpa_table);
        $this->db->where($where);
        $query = $this->db->get();
        return $query->num_rows();
    }
    
    function get_ab_cpa_list($where,$page,$limit){
        $this->db->select($this->plat_ab_cpa_table.'.*,'.$this->users_table.".username,".$this->plat_table.".name_ch,".$this->plat_table.".name_en,".$this->plat_table.".plat_period");
        $this->db->from($this->plat_ab_cpa_table);
        $this->db->join($this->users_table,$this->users_table.'.user_id = '.$this->plat_ab_cpa_table.'.user_id');
        $this->db->join($this->plat_table,$this->plat_table.'.id = '.$this->plat_ab_cpa_table.'.plat_id');
        $this->db->where($where);
        $this->db->order_by('reg_time','desc');
        $this->db->limit($limit, $page);
        return $this->db->get()->result_array();
    }
    
    function get_ab_cpa_count($where){
        $this->db->select('*');
        $this->db->from($this->plat_ab_cpa_table);
        $this->db->where($where);
        $query = $this->db->get();
        return $query->num_rows();
    }
    
     //插入数据
    function insert_ab($data)
    {
            $this->db->insert($this->plat_ab_cpa_table, $data);
            if($this->db->affected_rows()){
               return $this->db->insert_id();
            }else{
                return 0;
            }
    }
    
     //插入数据
    function insert_ac($data)
    {
            $this->db->insert($this->plat_ac_cpa_table, $data);
            if($this->db->affected_rows()){
               return $this->db->insert_id();
            }else{
                return 0;
            }
    }
    
    //更新数据
    function update_ab($data,$id)
    {
            return $this->db->where('id',$id)->update($this->plat_ab_cpa_table, $data);
    }
    //更新数据
    function update_ac($data,$id)
    {
            return $this->db->where('id',$id)->update($this->plat_ac_cpa_table, $data);
    }
    
    //删除数据
    function dalete($delid)
    {	
            $this->db->where('id',$delid);
            $this->db->delete($this->table);
            return $this->db->affected_rows();
    }
    
    //设置状态
    function setstatus($status,$ids)
    {
            return $this->db->where_in('id',$ids)->update($this->table, array('status'=>$status));
    }
}
